/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dataBase;

import apunte.Apunte;
import apunte.ManejoApunte;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import javax.swing.JOptionPane;

/**
 *
 * @author martinLequerica
 */
public class Busquedas {

    private Db db;

    public Busquedas() {

        db = new Db();


    }

    /**
     * 
     * @param obj 
     * @param lls
     * @return
     */
    public ResultSet buscar(ObjBusqueda[] obj) throws SQLException {


        String sql = "";
        int cnt = 0;
        for (int i = 0; i < obj.length; i++) {

            if (obj[i] != null) {

                if (cnt == 0) {



                    sql += "select * from " + obj[i].getTabla() + "";
                } else {

                    if (cnt == 1 && obj[1] != null) {
                    } else {
                        sql += "," + obj[i].getTabla();
                    }
                }
                cnt++;
            }


        }

        cnt = 0;

        for (int i = 0; i < obj.length; i++) {
            if (obj[i] != null) {


                if (cnt == 0) {

                    sql += " where " + obj[i].getColumna() + " = '" + obj[i].getDato() + "'";

                } else {
                    sql += " && " + obj[i].getColumna() + " = '" + obj[i].getDato() + "'";
                }
                cnt++;
            }
        }
        Statement st = db.getStatement();
        System.out.println(sql);
        ResultSet eq = st.executeQuery(sql);

        return eq;


    }
    
    


    
}
